package xyz.lilei23.framework.bean;

import xyz.lilei23.framework.core.BeanDefinition;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * 普通bean定义 后续可细分为内部bean 根bean
 * @author jack
 * @date 31/07/2021 16:20
 * @version 1.0
 **/
public class GenericBeanDefinition implements BeanDefinition {
    private String id;

    private String className;

    private Class<?> beanClass;

    private List<Arg> args = new LinkedList<>();

    private List<PropertyArg> propertiesArgs = new LinkedList<>();

    private Scope scope = Scope.SINGLETON;

    private boolean lazyInit = false;

    public static enum Scope{
        /**
         * 作用域
         */
        SINGLETON,
        PROTOTYPE
    }

    public boolean isSingle(){
        return Scope.SINGLETON.equals(scope);
    }

    public List<PropertyArg> getPropertiesArgs() {
        return propertiesArgs;
    }

    public void setPropertiesArgs(List<PropertyArg> propertiesArgs) {
        this.propertiesArgs = propertiesArgs;
    }

    public static class Arg{
        private boolean isRef;
        private Class<?> type;
        private String arg;
        private String value;

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public boolean isRef() {
            return isRef;
        }

        public void setRef(boolean ref) {
            isRef = ref;
        }

        public Class<?> getType() {
            return type;
        }

        public void setType(Class<?> type) {
            this.type = type;
        }

        public String getArg() {
            return arg;
        }

        public void setArg(String arg) {
            this.arg = arg;
        }
    }

    public static class PropertyArg{
        private Class<?> type;
        private String name;
        private String ref;
        private String value;
        private String parentId;


        public Class<?> getType() {
            return type;
        }

        public void setType(Class<?> type) {
            this.type = type;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getRef() {
            return ref;
        }

        public void setRef(String ref) {
            this.ref = ref;
        }

        public String getParentId() {
            return parentId;
        }

        public void setParentId(String parentId) {
            this.parentId = parentId;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }

    public static class AutowiredArg{
        private Class<?> type;
        private String name;
        private Field autoField;

        public Class<?> getType() {
            return type;
        }

        public void setType(Class<?> type) {
            this.type = type;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Field getAutoField() {
            return autoField;
        }

        public void setAutoField(Field autoField) {
            this.autoField = autoField;
        }
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public Class<?> getBeanClass() {
        return beanClass;
    }

    public void setBeanClass(Class<?> beanClass) {
        this.beanClass = beanClass;
    }

    public List<Arg> getArgs() {
        return args;
    }

    public void setArgs(List<Arg> args) {
        this.args = args;
    }

    public Scope getScope() {
        return scope;
    }

    public void setScope(Scope scope) {
        this.scope = scope;
    }

    public boolean isLazyInit() {
        return lazyInit;
    }

    public void setLazyInit(boolean lazyInit) {
        this.lazyInit = lazyInit;
    }
}
